using System;
using System.Globalization;
using System.IO.Ports;
using System.Windows;
using System.Windows.Data;

namespace SerialPortCommunicationProject
{
    [ValueConversion(typeof(StopBits), typeof(string))]
    public class StopBitsConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            StopBits re = (StopBits)value;
            switch (re)
            {
                case StopBits.One:
                    return "1";
                case StopBits.Two:
                    return "2";
                case StopBits.OnePointFive:
                    return "1.5";
                default:
                    return "请选择";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string strValue = value as string;
            switch (strValue)
            {
                case "1":
                    return StopBits.One;
                case "2":
                    return StopBits.Two;
                case "1.5":
                    return StopBits.OnePointFive;
            }
            return DependencyProperty.UnsetValue;
        }
    }
}

    
